var API = require("../../api/common");
var server = "";

function getServerAndFixUrl(url) {
    API.getResourceUrl().then((res) => {
        if (res.data.status == 200) {
            server = res.data.datas;
            console.log(server + url);
            return server + url;
        } else {
            return url;
        }
    });
}

export function fixUrl(url) {
    console.log("fixUrl server", server);
    if (url && url.length > 0 && url.toLowerCase().indexOf("http:") != 0) {
        if (server && server.length > 0) {
            return server + url;
        }
        else {
            return getServerAndFixUrl(url);
        }

    }
    return url;
}